import { nextTick } from 'vue'
import { useGlobalStore } from '@/stores/global'
import { useKeepAliveStore } from '@/stores/keepAlive'

export function useRefresh() {
  const globalStore = useGlobalStore()

  /**
   * 刷新当前页面
   * @param {Route} route 页面路由
   */
  const refreshPage = (route) => {
    setTimeout(() => {
      route.meta.isKeepAlive && useKeepAliveStore().removeKeepAlive(route.name)
      globalStore.isShowPage = false
      nextTick(() => {
        route.meta.isKeepAlive && useKeepAliveStore().addKeepAlive(route.name)
        globalStore.isShowPage = true
      })
    }, 0)
  }

  return {
    refreshPage
  }
}
